{% extends "base/front.html" %}

{% block title %}{{ data['title'] }}{% endblock %}

{% block head %}
    <style type="text/css">
        fieldset{padding:.35em .625em .75em;margin:0 2px;border:1px solid #009;border-radius:5px;}
        legend{padding:.5em;border:0;width:auto}
        img{max-width: 100%}
    </style>
    {% if blog_show_header_include %}
        {% for bi in blog_show_header_include() %}
            {% include bi %}
        {% endfor %}
    {% endif %}
    {% if blog_show_header_string %}
        {% for bs in blog_show_header_string() %}
            {{ bs|safe }}
        {% endfor %}
    {% endif %}
{% endblock %}

{% block PathNavigation %}
			<ul class="breadcrumb">
				<li>
					<a href="{{ url_for('front.index') }}">首页</a>
				</li>
                <li>
                    <a href="{{ url_for('front.blogResource', resource_type='catalog', resource_data=data.catalog) }}" title="查看 {{ data.catalog }} 分类中所有文章">{{ data.catalog }}</a>
                </li>
				<li class="active">
					{{ data.title }}
				</li>
			</ul>
{% endblock %}

{% block container %}
            <!-- 文章详情 -->
            <article>
                <header>
			        <h3 class="text-center text-success">{{ data['title'] }}
                    {% if data.get("sources") == "原创" %}
                        <attr title="原创文章"><img src="{{ url_for('static', filename='img/Original.gif') }}"></attr>
                    {% elif data.get("sources") == "转载" %}
                        <attr title="转载文章"><img src="{{ url_for('static', filename='img/Reprint.gif') }}"></attr>
                    {% elif data.get("sources") == "翻译" %}
                        <attr title="翻译文章"><img src="{{ url_for('static', filename='img/Translate.gif') }}"></attr>
                    {% endif %}
                    </h3>
			    </header>
                <fieldset>
                    <legend><small class="text-info text-lowercase">功能区</small></legend>
                    {% set admins = g.api.user_get_admins().data %}
                    <div class="btn-group" role="group" aria-label="...">
                        {% if g.signin and g.username == data.author or g.username in admins %}
                            <a href="{{ url_for('front.blogEdit', blogId=blogId) }}" style='color:blue'><button type="button" class="btn btn-warning">编辑文章</button></a>
                            <a href="javascript:delBlog()" style='color:blue'><button type="button" class="btn btn-danger">删除文章</button></a>
                        {% endif %}
                        {% if g.username in admins %}
                            {% if data.top in ('true', 'True', True) %}
                                <a href="javascript:setTop(false)" style='color:blue'><button type="button" class="btn btn-primary">取消置顶</button></a>
                            {% else %}
                                <a href="javascript:setTop(true)" style='color:blue'><button type="button" class="btn btn-primary">置顶文章</button></a>
                            {% endif %}
                            {% if data.recommend in ('true', 'True', True) %}
                                <a href="javascript:setRecommend(false)" style='color:blue'><button type="button" class="btn btn-info">取消推荐</button></a>
                            {% else %}
                                <a href="javascript:setRecommend(true)" style='color:blue'><button type="button" class="btn btn-info">推荐文章</button></a>
                            {% endif %}
                        {% endif %}
                    </div>
                    <h6>
                        {% if data.author %}
                        <i class="icon-user icon-1x"></i><a href="{{ url_for('front.userHome', user=data.author) }}" title="由 {{ data.author }} 发布" style="color: #999">&nbsp;{{ data.author }}</a>&nbsp;
                        {% endif %}

                        {% if data.catalog %}
                        <i class="icon-folder-open icon-1x"></i><a href="{{ url_for('front.blogResource', resource_type='catalog', resource_data=data.catalog) }}" title="查看 {{ data.catalog }} 分类中所有文章" style="color: #999">&nbsp;{{ data.catalog }}</a>&nbsp;
                        {% endif %}

                        {% if data.tag %}
                        <i class="icon-tag icon-1x"></i>
                        {% for tag in data.tag.split() %}
                            <a href="{{ url_for('front.blogResource', resource_type='tag', resource_data=tag) }}" title="查看 {{ tag }} 标签中所有文章" style="color: #999">{{ tag }}</a>&nbsp;
                        {% endfor %}
                        {% endif %}

                        {% if data.create_time %}
                        <i class="icon-calendar icon-1x"></i><scan style="color: #999">&nbsp;{{ data.create_time }}</scan>&nbsp;
                        {% endif %}

                        {%- if g.plugins.ChangyanComment.enable in ('true', 'True', True) %}
                        <i class="icon-comment-alt icon-1x"></i>&nbsp;评论<a href="#SOHUCS">{{ g.api.misc_get_commend(blogId).data.comments }}</a>次&nbsp;
                        {% endif %}

                        {% if BaiduActivePushResult %}
                            <scan class="text-success"><i class="icon-ok-circle icon-1x"></i>&nbsp;百度主动推送成功</scan>
                        {% else %}
                            <scan class="text-danger"><i class="icon-ok-circle icon-1x"></i>&nbsp;百度主动推送失败</scan>
                        {% endif %}

                        {% if g.plugins.BaiduIncludedCheck in ("true", "True", True) %}
                            <scan id="BaiduIncludedCheck"></scan>
                        {% endif %}

                        {% if blog_show_funcarea_include %}
                            {% for sfi in blog_show_funcarea_include() %}
                                {% include sfi %}
                            {% endfor %}
                        {% endif %}
                        {% if blog_show_funcarea_string %}
                            {% for sfs in blog_show_funcarea_string() %}
                                {{ sfs|safe }}
                            {% endfor %}
                        {% endif %}
                    </h6>
                </fieldset>
                <fieldset>
                    <legend><small class="text-success text-lowercase">正文区</small></legend>
				    {{ data['content'] | safe }}
                </fieldset>
                {%- if data.get("sources") == "原创" %}
                <p></p>
                <div class="alert alert-success alert-dismissible" role="alert">
                    <b>版权声明</b>：<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;本文为原创文章，由 {{ g.api.get_sys_config().data.about_awi }} 创作和发表，版权所有，转载请注明作者及出处！<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;本文标题是：{{ data['title'] }}， 本文来源地址：<a href="{{ request.url }}" class="alert-link">{{ request.url }}</a>
                </div>
                {% endif -%}
            </article>
            <p></p>

            {% if blog_show_content_include %}
                {% for ci in blog_show_content_include() %}
                    {% include ci %}
                {% endfor %}
            {% endif %}

            {%- if g.plugins.Reward in ('true', 'True', True) or g.plugins.Like in ('true', 'True', True) %}
                <!--点赞、打赏-->
                <div class="thumbs_content">
                    {% if g.plugins.Like in ('true', 'True', True) %}
                    <a href="javascript:void(0)" class="thumbs_button fa fa-thumbs-up" title="点赞, 支持一下"> 点赞</a>
                    {% endif %}
                </div>
            {% endif -%}

            {%- if g.plugins.ChangyanComment.enable in ('true', 'True', True) %}
                <!-- 畅言评论框插件,PC和WAP自适应版 -->
                <div id="SOHUCS" sid="{{ blogId }}" ></div> 
                <script type="text/javascript"> 
                (function(){ 
                    var appid = '{{ g.plugins.ChangyanComment.appid }}'; 
                    var conf = '{{ g.plugins.ChangyanComment.appkey }}'; 
                    var width = window.innerWidth || document.documentElement.clientWidth; 
                    if (width < 960) { 
                        window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); 
                </script>
            {% endif -%}
{% endblock %}

{% block script %}
{% if blog_show_script_include %}
    {% for si in blog_show_script_include() %}
        {% include si %}
    {% endfor %}
{% endif %}

<script type="text/javascript">
{% if g.username in g.api.user_get_admins().data %}
// 设置或取消置顶文章
function setTop(value) {
    $.ajax({
        url: "{{ url_for('api.misc') }}?action=top&blogId={{ blogId }}&value=" + value,
        method: 'POST',
        datatype: 'json',
        success: function(res) {
            console.log(res);
            if (res.success==true) {
                if(value==false) {
                    layer.msg("取消置顶成功！");
                } else {
                    layer.msg("置顶文章成功！");
                }
            } else {
                if(value==false) {
                    layer.msg("取消置顶失败！"+res.msg, {icon: 2, time: 15*1000});
                } else {
                    layer.msg("置顶文章失败！"+res.msg, {icon: 2, time: 15*1000});
                }
            }
            document.location.reload()
        },
        error: function(error){
            console.log(error);
        }
    });
}

// 设置或取消推荐文章
function setRecommend(value) {
    $.ajax({
        url: "{{ url_for('api.misc') }}?action=recommend&blogId={{ blogId }}&value=" + value,
        method: 'POST',
        datatype: 'json',
        success: function(res) {
            console.log(res);
            if (res.success==true) {
                if(value==false) {
                    layer.msg("取消推荐成功！");
                } else {
                    layer.msg("推荐文章成功！");
                }
            } else {
                if(value==false) {
                    layer.msg("取消推荐失败！"+res.msg, {icon: 2, time: 15*1000});
                } else {
                    layer.msg("推荐文章失败！"+res.msg, {icon: 2, time: 15*1000});
                }
            }
            document.location.reload()
        },
        error: function(error){
            console.log(error);
        }
    });
}

// 删除文章
function delBlog() {
    layer.confirm('你确定要删除此文章?', {
        btn: ['确认删除','我再想想']
    }, function(){
        console.warn("将要删除节点"+{{ blogId }});
        $.ajax({
            url: "{{ url_for('api.blog', blogId=blogId) }}",
            method: 'DELETE',
            async: false,
            datatype: 'json',
            success: function(res) {
                console.log(res);
                if (res.success==true) {
                    layer.msg("删除文章成功！", {icon: 1, time: 3*1000});
                    window.location.href="{{ url_for('front.index') }}";
                } else {
                    layer.msg("删除文章失败！"+res.msg, {icon: 2, time: 15*1000});
                }
            },
            error: function(error){
                console.log(error);
                layer.alert(res.statusText);
            }
        });
    }, function() {
        console.log("canel delete blog");
    });
}
{% endif %}
</script>
{% endblock %}
